package com.pilipili.zeus.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pilipili.commonutils.Result;
import com.pilipili.zeus.eduService.entity.EduCourse;
import com.pilipili.zeus.eduService.entity.EduTeacher;
import com.pilipili.zeus.eduService.service.EduCourseService;
import com.pilipili.zeus.eduService.service.impl.EduTeacherServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Unlimited_Blade_Works
 */
@RestController
@RequestMapping("/eduService/front")
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherServiceImpl teacherService;

    @ApiOperation(value = "前台获取首页作者、番剧数据")
    @GetMapping("index")
    public Result index(){
        QueryWrapper<EduCourse> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByDesc("buy_count");
        queryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(queryWrapper);
        QueryWrapper<EduTeacher> query = new QueryWrapper<>();
        query.orderByDesc("level");
        query.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(query);
        return Result.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
}
